
public class Consumer<T extends Comparable<T>> extends Prosumer<T> implements Runnable {
    Consumer(int id, SyncHeap<T> sHeap, javax.swing.JLabel cLabel, double consTime, 
            boolean useRandom, boolean printToStd) {
        super(id, sHeap, cLabel, consTime, useRandom, printToStd);
        m_sH.addConsumer();
    }
    @Override
    protected void process() {
	boolean woken = false;
	try { 
            T obj = (T)(m_sH.getTop());
	    while (!obj.equals(m_sH.getPoisson())) {
		obj = (T)(m_sH.removeTop());
		if (!obj.equals(m_sH.getPoisson())) {
                    String tempStr = "Consumer "+m_id+" (running thread \""+Thread.currentThread().getName()+"\") consumed \""+obj+"\"";
		    if (m_printToStd) System.out.println(tempStr);
                    m_label.setText(tempStr);
                    if (m_useRandom) m_processTime = m_rand.nextFloat() * 5000;
                    Thread.sleep( (int)(m_processTime) );  //working with consuming elem...
		}
	    }
	} catch(InterruptedException e) {
	    //Since it sleeps now and then interrupt will work (no need to put any flag)
	    if (m_printToStd) System.out.println("Consumer " + m_id + " interrupted while processing an element (sleeping).");
	    woken = true;
	    m_sH.withdrawConsumer(); //Just to not get a producer hanging in case of full heap...
	}
	if ((!woken)&&(m_printToStd)) System.out.println("Consumer " + m_id + " interrupted while waiting due to empty heap (found a poisson).");
    }
};